﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace testDatabase
{
    public class testClassttt
    {

        /// <summary>
        /// 尋找.dll並取得路徑
        /// </summary>
        /// <returns>所有.dll的路徑</returns>
        public static List<string> FindDll(string directory)
        {
            List<string> DbProviderPaths = new List<string>();
            try
            {
                string path = MapPath(directory); //所在的目錄為"./DbProvider"
                foreach (string filePath in Directory.GetFiles(path, "*.dll"))
                {
                    DbProviderPaths.Add(filePath);
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return DbProviderPaths;
        }

        /// <summary>
        /// 回傳實體檔案路徑
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public static string MapPath(string strPath)
        {
            if (HttpContext.Current != null)
            {
                return HttpContext.Current.Server.MapPath(strPath);
            }
            else //非web程序引用
            {
                strPath = strPath.Replace("/", "\\");
                if (strPath.StartsWith("\\"))
                {
                    strPath = strPath.TrimStart('\\');
                }
                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }

    }
}